USE [WorldBankBBS]
GO
/****** Object:  Table [dbo].[User]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[User](
	[UserUID] [uniqueidentifier] NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[EMailAddress] [nvarchar](512) NOT NULL,
	[Password] [char](16) NOT NULL,
	[Alias] [nvarchar](256) NULL,
	[RealName] [nvarchar](256) NULL,
	[IsDeleted] [bit] NOT NULL,
	[IsValidated] [bit] NOT NULL,
	[Website] [nvarchar](2048) NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[UserUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Log]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Log](
	[LogUID] [uniqueidentifier] NOT NULL,
	[Message] [nvarchar](max) NOT NULL,
	[Extended] [ntext] NULL,
	[Timestamp] [datetime] NOT NULL,
	[Type] [nvarchar](50) NULL,
	[SessionUID] [uniqueidentifier] NULL,
 CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED 
(
	[LogUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Sig]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Sig](
	[SigUID] [uniqueidentifier] NOT NULL,
	[SigName] [nvarchar](50) NOT NULL,
	[SigDescription] [ntext] NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Sig] PRIMARY KEY CLUSTERED 
(
	[SigUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Subboard]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Subboard](
	[SubboardUID] [uniqueidentifier] NOT NULL,
	[SubboardName] [nvarchar](256) NOT NULL,
	[SubboardDescription] [ntext] NULL,
	[SigUID] [uniqueidentifier] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Subboard] PRIMARY KEY CLUSTERED 
(
	[SubboardUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[SigUser]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SigUser](
	[SigUID] [uniqueidentifier] NOT NULL,
	[UserUID] [uniqueidentifier] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
	[IsSigOp] [bit] NOT NULL,
	[CanRead] [bit] NOT NULL,
	[CanWrite] [bit] NOT NULL,
 CONSTRAINT [PK_SigUser] PRIMARY KEY CLUSTERED 
(
	[SigUID] ASC,
	[UserUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Session]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Session](
	[SessionUID] [uniqueidentifier] NOT NULL,
	[StartedOn] [datetime] NOT NULL,
	[EndedOn] [datetime] NULL,
	[UserUID] [uniqueidentifier] NULL,
	[RemoteIP] [nvarchar](50) NULL,
	[Encoding] [nchar](10) NOT NULL,
 CONSTRAINT [PK_Session] PRIMARY KEY CLUSTERED 
(
	[SessionUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PrivateMail]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PrivateMail](
	[PrivateMailUID] [uniqueidentifier] NOT NULL,
	[FromUserUID] [uniqueidentifier] NOT NULL,
	[ToUserUID] [uniqueidentifier] NOT NULL,
	[Subject] [nvarchar](256) NOT NULL,
	[Body] [ntext] NOT NULL,
	[Timestamp] [datetime] NOT NULL,
	[IsRead] [bit] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
	[HasReplied] [bit] NOT NULL,
 CONSTRAINT [PK_PrivateMail] PRIMARY KEY CLUSTERED 
(
	[PrivateMailUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Fileboard]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Fileboard](
	[FileboardUID] [uniqueidentifier] NOT NULL,
	[FileboardName] [nvarchar](256) NOT NULL,
	[FileboardDescription] [ntext] NULL,
	[SigUID] [uniqueidentifier] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Fileboard] PRIMARY KEY CLUSTERED 
(
	[FileboardUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Thread]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Thread](
	[ThreadUID] [uniqueidentifier] NOT NULL,
	[ThreadName] [nvarchar](256) NOT NULL,
	[ThreadDescription] [ntext] NULL,
	[SubboardUID] [uniqueidentifier] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Thread] PRIMARY KEY CLUSTERED 
(
	[ThreadUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[File]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[File](
	[FileUID] [uniqueidentifier] NOT NULL,
	[FileboardUID] [uniqueidentifier] NOT NULL,
	[Filename] [nvarchar](512) NOT NULL,
	[Description] [ntext] NULL,
	[UploadedByUserUID] [uniqueidentifier] NULL,
	[Timestamp] [datetime] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_File] PRIMARY KEY CLUSTERED 
(
	[FileUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Message]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Message](
	[MessageUID] [uniqueidentifier] NOT NULL,
	[ThreadUID] [uniqueidentifier] NOT NULL,
	[FromUserUID] [uniqueidentifier] NOT NULL,
	[ToUserUID] [uniqueidentifier] NULL,
	[Subject] [nvarchar](256) NOT NULL,
	[MessageBody] [ntext] NOT NULL,
	[Timestamp] [datetime] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_Message] PRIMARY KEY CLUSTERED 
(
	[MessageUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object:  Table [dbo].[MessageUser]    Script Date: 05/20/2014 20:46:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[MessageUser](
	[MessageUID] [uniqueidentifier] NOT NULL,
	[UserUID] [uniqueidentifier] NOT NULL,
	[IsRead] [bit] NOT NULL,
	[IsHidden] [bit] NOT NULL,
	[ReadOn] [datetime] NOT NULL,
 CONSTRAINT [PK_MessageUser] PRIMARY KEY CLUSTERED 
(
	[MessageUID] ASC,
	[UserUID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Default [DF_File_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[File] ADD  CONSTRAINT [DF_File_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_Fileboard_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Fileboard] ADD  CONSTRAINT [DF_Fileboard_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_Message_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Message] ADD  CONSTRAINT [DF_Message_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_MessageUser_IsRead]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[MessageUser] ADD  CONSTRAINT [DF_MessageUser_IsRead]  DEFAULT ((0)) FOR [IsRead]
GO
/****** Object:  Default [DF_MessageUser_IsHidden]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[MessageUser] ADD  CONSTRAINT [DF_MessageUser_IsHidden]  DEFAULT ((0)) FOR [IsHidden]
GO
/****** Object:  Default [DF_PrivateMail_IsRead]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[PrivateMail] ADD  CONSTRAINT [DF_PrivateMail_IsRead]  DEFAULT ((0)) FOR [IsRead]
GO
/****** Object:  Default [DF_PrivateMail_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[PrivateMail] ADD  CONSTRAINT [DF_PrivateMail_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_PrivateMail_HasReplied]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[PrivateMail] ADD  CONSTRAINT [DF_PrivateMail_HasReplied]  DEFAULT ((0)) FOR [HasReplied]
GO
/****** Object:  Default [DF_Sig_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Sig] ADD  CONSTRAINT [DF_Sig_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_SigUser_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser] ADD  CONSTRAINT [DF_SigUser_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_SigUser_IsSigOp]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser] ADD  CONSTRAINT [DF_SigUser_IsSigOp]  DEFAULT ((0)) FOR [IsSigOp]
GO
/****** Object:  Default [DF_SigUser_CanRead]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser] ADD  CONSTRAINT [DF_SigUser_CanRead]  DEFAULT ((1)) FOR [CanRead]
GO
/****** Object:  Default [DF_SigUser_CanWrite]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser] ADD  CONSTRAINT [DF_SigUser_CanWrite]  DEFAULT ((0)) FOR [CanWrite]
GO
/****** Object:  Default [DF_Subboard_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Subboard] ADD  CONSTRAINT [DF_Subboard_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_Thread_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Thread] ADD  CONSTRAINT [DF_Thread_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_User_IsDeleted]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_User_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO
/****** Object:  Default [DF_User_IsValidated]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[User] ADD  CONSTRAINT [DF_User_IsValidated]  DEFAULT ((0)) FOR [IsValidated]
GO
/****** Object:  ForeignKey [FK_File_Fileboard]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[File]  WITH CHECK ADD  CONSTRAINT [FK_File_Fileboard] FOREIGN KEY([FileboardUID])
REFERENCES [dbo].[Fileboard] ([FileboardUID])
GO
ALTER TABLE [dbo].[File] CHECK CONSTRAINT [FK_File_Fileboard]
GO
/****** Object:  ForeignKey [FK_File_User]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[File]  WITH CHECK ADD  CONSTRAINT [FK_File_User] FOREIGN KEY([UploadedByUserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[File] CHECK CONSTRAINT [FK_File_User]
GO
/****** Object:  ForeignKey [FK_Fileboard_Sig]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Fileboard]  WITH CHECK ADD  CONSTRAINT [FK_Fileboard_Sig] FOREIGN KEY([SigUID])
REFERENCES [dbo].[Sig] ([SigUID])
GO
ALTER TABLE [dbo].[Fileboard] CHECK CONSTRAINT [FK_Fileboard_Sig]
GO
/****** Object:  ForeignKey [FK_Message_Thread]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_Thread] FOREIGN KEY([ThreadUID])
REFERENCES [dbo].[Thread] ([ThreadUID])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_Thread]
GO
/****** Object:  ForeignKey [FK_Message_User_From]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_User_From] FOREIGN KEY([FromUserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_User_From]
GO
/****** Object:  ForeignKey [FK_Message_User_To]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Message]  WITH CHECK ADD  CONSTRAINT [FK_Message_User_To] FOREIGN KEY([ToUserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[Message] CHECK CONSTRAINT [FK_Message_User_To]
GO
/****** Object:  ForeignKey [FK_MessageUser_Message]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[MessageUser]  WITH CHECK ADD  CONSTRAINT [FK_MessageUser_Message] FOREIGN KEY([MessageUID])
REFERENCES [dbo].[Message] ([MessageUID])
GO
ALTER TABLE [dbo].[MessageUser] CHECK CONSTRAINT [FK_MessageUser_Message]
GO
/****** Object:  ForeignKey [FK_MessageUser_User]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[MessageUser]  WITH CHECK ADD  CONSTRAINT [FK_MessageUser_User] FOREIGN KEY([UserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[MessageUser] CHECK CONSTRAINT [FK_MessageUser_User]
GO
/****** Object:  ForeignKey [FK_PrivateMail_User_From]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[PrivateMail]  WITH CHECK ADD  CONSTRAINT [FK_PrivateMail_User_From] FOREIGN KEY([FromUserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[PrivateMail] CHECK CONSTRAINT [FK_PrivateMail_User_From]
GO
/****** Object:  ForeignKey [FK_PrivateMail_User_To]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[PrivateMail]  WITH CHECK ADD  CONSTRAINT [FK_PrivateMail_User_To] FOREIGN KEY([ToUserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[PrivateMail] CHECK CONSTRAINT [FK_PrivateMail_User_To]
GO
/****** Object:  ForeignKey [FK_Session_User]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Session]  WITH CHECK ADD  CONSTRAINT [FK_Session_User] FOREIGN KEY([UserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[Session] CHECK CONSTRAINT [FK_Session_User]
GO
/****** Object:  ForeignKey [FK_SigUser_Sig]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser]  WITH CHECK ADD  CONSTRAINT [FK_SigUser_Sig] FOREIGN KEY([SigUID])
REFERENCES [dbo].[Sig] ([SigUID])
GO
ALTER TABLE [dbo].[SigUser] CHECK CONSTRAINT [FK_SigUser_Sig]
GO
/****** Object:  ForeignKey [FK_SigUser_User]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[SigUser]  WITH CHECK ADD  CONSTRAINT [FK_SigUser_User] FOREIGN KEY([UserUID])
REFERENCES [dbo].[User] ([UserUID])
GO
ALTER TABLE [dbo].[SigUser] CHECK CONSTRAINT [FK_SigUser_User]
GO
/****** Object:  ForeignKey [FK_Subboard_Sig]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Subboard]  WITH CHECK ADD  CONSTRAINT [FK_Subboard_Sig] FOREIGN KEY([SigUID])
REFERENCES [dbo].[Sig] ([SigUID])
GO
ALTER TABLE [dbo].[Subboard] CHECK CONSTRAINT [FK_Subboard_Sig]
GO
/****** Object:  ForeignKey [FK_Thread_Subboard]    Script Date: 05/20/2014 20:46:19 ******/
ALTER TABLE [dbo].[Thread]  WITH CHECK ADD  CONSTRAINT [FK_Thread_Subboard] FOREIGN KEY([SubboardUID])
REFERENCES [dbo].[Subboard] ([SubboardUID])
GO
ALTER TABLE [dbo].[Thread] CHECK CONSTRAINT [FK_Thread_Subboard]
GO
